<style type="text/css" media="screen">
    .empty{
        color:red;
        position: relative;
        top: 9px;
    }
</style>

<div class="layui-form" id="layuiadmin-form-admin" lay-filter="layuiadmin-form-admin" style="padding: 20px 30px 0 0;">
    <div class="layui-row">
        <fieldset class="layui-elem-field layui-field-title">
            <legend>
                <b>
                    基本信息
                </b>
            </legend>
        </fieldset>
        <div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    获得时间
                </label>
                <div class="layui-input-block">
                    <input autocomplete="off" class="layui-input" id="period" name="get_customer_time" value="{$model.get_customer_time??''}" placeholder="请输入获得客户时间" required="" type="text">
                    </input>
                </div>
            </div>
        </div>
        <div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    负责人
                </label>
                <div class="layui-input-block">
                    <select name="person_in_charge_id" lay-search="">
                        <option value="">请选择负责人</option>
                        {foreach $admin as $key=>$vo}
                            <option value="{$vo.id}" {if condition="($model.person_in_charge_id eq $vo.id)" }selected{/if}>{$vo.nickname}</option>
                        {/foreach}
                    </select>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-row">
        <fieldset class="layui-elem-field layui-field-title">
            <legend>
                <b>
                    公司信息
                </b>
            </legend>
        </fieldset>
        <div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    客户名称
                </label>
                <div class="layui-input-block">
                    <input autocomplete="off" class="layui-input" name="customer_name" value="{$model.customer_name??''}" placeholder="请输入客户名称" required="" type="text">
                    </input>
                </div>
            </div>
        </div>
        <div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    所在城市
                </label>
                <div class="layui-input-block">
                    <select name="city_id" lay-search="">
                        <option value="">请选择城市</option>
                        {foreach $customer_city as $key=>$vo}
                            <option value="{$vo.id}" {if condition="($model.city_id eq $vo.id)" }selected{/if}>{$vo.name}</option>
                        {/foreach}
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    行业
                </label>
                <div class="layui-input-block">
                    <select name="industry_id" lay-search="">
                        <option value="">请选择行业</option>
                        {foreach $industry as $key=>$vo}
                            <option value="{$vo.id}" {if condition="($model.industry_id eq $vo.id)" }selected{/if}>{$vo.name}</option>
                        {/foreach}
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    意向产品
                </label>
                <div class="layui-input-block">
                    <select name="intention_id" lay-search="">
                        <option value="">请选择意向产品</option>
                        {foreach $intention as $key=>$vo}
                              <option value="{$vo.id}" {if condition="($model.intention_id eq $vo.id)" }selected{/if}>{$vo.name}</option>
                        {/foreach}
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    公司座机
                </label>
                <div class="layui-input-block">
                    <input autocomplete="off" class="layui-input" value="{$model.plane ?? ''}" name="plane" placeholder="请输入公司座机" required="" type="text">
                    </input>
                </div>
            </div>
        </div>
        <div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    客户状态
                </label>
                <div class="layui-input-block">
                    <select name="customer_status_id" lay-search="">
                        <option value="">请选择客户状态</option>
                        {foreach $customer_status as $key=>$vo}
                             <option value="{$vo.id}" {if condition="($model.customer_status_id eq $vo.id)" }selected{/if}>{$vo.name}</option>
                        {/foreach}
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    客户类别
                </label>
                <div class="layui-input-block">
                    <select name="customer_type_id" lay-search="">
                        <option value="">请选择客户类别</option>
                        {foreach $customer_type as $key=>$vo}
                             <option value="{$vo.id}" {if condition="($model.customer_type_id eq $vo.id)" }selected{/if}>{$vo.name}</option>
                        {/foreach}
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    客户等级
                </label>
                <div class="layui-input-block">
                    <select name="customer_level_id" lay-search="">
                        <option value="">请选择客户等级</option>
                        {foreach $customer_level as $key=>$vo}
                              <option value="{$vo.id}" {if condition="($model.customer_level_id eq $vo.id)" }selected{/if}>{$vo.name}</option>
                        {/foreach}
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    客户来源
                </label>
                <div class="layui-input-block">
                    <select name="customer_source_id" lay-search="">
                        <option value="">请选择客户来源</option>
                        {foreach $customer_source as $key=>$vo}
                             <option value="{$vo.id}" {if condition="($model.customer_source_id eq $vo.id)" }selected{/if}>{$vo.name}</option>
                        {/foreach}
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    成熟度
                </label>
                <div class="layui-input-block">
                    <select name="maturity_id" lay-search="">
                        <option value="">请选择成熟度</option>
                        {foreach $customer_ripe as $key=>$vo}
                        <option value="{$vo.id}" {if condition="($model.maturity_id eq $vo.id)" }selected{/if}>{$vo.name}</option>
                        {/foreach}
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-col-xs12 layui-col-sm6 layui-col-md12">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    地址
                </label>
                <div class="layui-input-block">
                    <input autocomplete="off" class="layui-input" name="address" value="{$model.address ?? ''}" placeholder="请输入地址" required="" type="text">
                    </input>
                </div>
            </div>
        </div>
        <div class="layui-col-xs12 layui-col-sm6 layui-col-md12">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    客户介绍
                </label>
                <div class="layui-input-block">
                    <textarea class="layui-textarea" id="LAY_demo_editor" lay-verify="remarks" name="remarks">{$model.remarks ?? ''}</textarea>
                </div>
            </div>
        </div>
        <div class="layui-col-xs12 layui-col-sm6 layui-col-md12">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    相关附件
                </label>
                <div class="layui-input-block">
                         {volist name="customer_appendix" id="vo" empty="$empty"}
                         <p>{$vo.name}&nbsp;&nbsp;<a name="appendix" style="color:red;cursor:pointer" data-id={$vo.id} data-name="{$vo.name}" data-type="one">删除</a></p>
                          {/volist}
                        {notempty name="customer_appendix"}
                             <a name="appendix" data-id="{$model.id}" data-name="全部" data-type="all"  style="color:red;cursor:pointer">删除全部</a>
                           {/notempty}
                </div>
            </div>
        </div>
        <div class="layui-col-xs12 layui-col-sm6 layui-col-md12">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    相关文档
                </label>
                <div class="layui-input-block" id="layui-file">
                    <div class="layui-upload">
                        <button class="layui-btn layui-btn-normal" id="testList" type="button">
                            选择多文件
                        </button>
                        <div class="layui-upload-list">
                            <table class="layui-table">
                                <thead>
                                    <tr>
                                        <th>
                                            文件名
                                        </th>
                                        <th>
                                            大小
                                        </th>
                                        <th>
                                            状态
                                        </th>
                                        <th>
                                            操作
                                        </th>
                                    </tr>
                                </thead>
                                <tbody id="demoList">
                                </tbody>
                            </table>
                        </div>
                        <button class="layui-btn" id="testListAction" type="button">
                            开始上传
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-row">
        <fieldset class="layui-elem-field layui-field-title">
            <legend>
                <b>
                    联系人
                </b>
            </legend>
        </fieldset>
        <div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    姓名
                </label>
                <div class="layui-input-block">
                    <input autocomplete="off" class="layui-input" name="title" value="{$model.title ?? ''}" placeholder="请输入获得客户时间" required="" type="text">
                    </input>
                </div>
            </div>
        </div>
        <div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    性别
                </label>
                <div class="layui-input-block">
		 			{if $model['sex'] eq 1}
		            <input type="radio" name="sex" value="1" title="男1" checked>
		            <input type="radio" name="sex" value="0" title="女2">
		            {else}
		            <input type="radio" name="sex" value="1" title="男3">
		            <input type="radio" name="sex" value="0" title="女4" checked>
		            {/if}
                </div>
            </div>
        </div>
    </div>
    <div class="layui-row">
        <div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
            <div class="layui-form-item layui-inline">
                <label class="layui-form-label">
                    生日
                </label>
                <div class="layui-input-inline">
                   <select name="calendar_id">
                        <option value="0" {if condition="($model.calendar_id eq 0)" }selected{/if}>阳历</option>
                        <option value="1" {if condition="($model.calendar_id eq 1)" }selected{/if}>阴历</option>
                    </select>

                </div>
                <div class="layui-input-inline">
                    <input  class="layui-input" value="{$model.birthday ?? ''}" id="birthday" name="birthday" placeholder="请输入生日" required="" type="text" />
                </div>
            </div>
        </div>
        <div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    职务
                </label>
                <div class="layui-input-block">
                    <input autocomplete="off" class="layui-input" name="duties"  value="{$model.duties ?? ''}"  placeholder="请输入负责人" required="" type="text">
                    </input>
                </div>
            </div>
        </div>
        <div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    称呼
                </label>
                <div class="layui-input-block">
                    <input autocomplete="off" class="layui-input" name="customer_call" value="{$model.customer_call ?? ''}" placeholder="请输入称呼" required="" type="text">
                    </input>
                </div>
            </div>
        </div>
        <div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    手机号
                </label>
                <div class="layui-input-block">
                    <input autocomplete="off" class="layui-input" name="customer_phone" value="{$model.customer_phone ?? ''}" placeholder="请输入手机号" required="" type="text">
                    </input>
                </div>
            </div>
        </div>
        <div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    联系人座机
                </label>
                <div class="layui-input-block">
                    <input autocomplete="off" class="layui-input" name="contact_line" value="{$model.contact_line ?? ''}" placeholder="请输入联系人座机" required="" type="text">
                    </input>
                </div>
            </div>
        </div>
        <div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    邮箱
                </label>
                <div class="layui-input-block">
                    <input autocomplete="off" class="layui-input" name="email" value="{$model.email ?? ''}" placeholder="请输入邮箱" required="" type="text">
                    </input>
                </div>
            </div>
        </div>
        <div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    qq
                </label>
                <div class="layui-input-block">
                    <input autocomplete="off" class="layui-input" name="qq" value="{$model.qq ?? ''}" placeholder="请输入qq" required="" type="text">
                    </input>
                </div>
            </div>
        </div>
        <div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    微信号
                </label>
                <div class="layui-input-block">
                    <input autocomplete="off" class="layui-input" name="wechat" value="{$model.wechat ?? ''}" placeholder="请输入微信号" required="" type="text">
                    </input>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-form-item layui-hide">
        <input id="LAY-user-back-submit" lay-filter="LAY-user-back-submit" lay-submit="" type="button" value="确认">
        </input>
    </div>
</div>
<script src="/static/admin/layui/layui.js">
</script>
<script>
    layui.config({
        base: '/static/admin/' //静态资源所在路径
    }).extend({
        index: 'lib/index', //主入口模块
        treeTable: '../admin/lib/extend/authtree'
    }).use(['index', 'form', 'laydate','upload'], function () {
        var $ = layui.$, form = layui.form, laydate = layui.laydate ,upload = layui.upload;
        //日期范围
        laydate.render({
            elem: '#period'
            , trigger: 'click'//呼出事件改成click
        });
  laydate.render({
            elem:'#birthday',
            trigger:'click',
            format: 'MM-dd' //可任意组合
        });

//多文件列表示例
var j=0;
  var demoListView = $('#demoList')
  ,uploadListIns = upload.render({
    elem: '#testList'
    ,url: "{:url('customer/upload')}"
    ,accept: 'file'
    ,multiple: true
    ,auto: false
    ,bindAction: '#testListAction'
    ,choose: function(obj){   
      var files = this.files = obj.pushFile(); //将每次选择的文件追加到文件队列
      //读取本地文件
      obj.preview(function(index, file, result){
        var tr = $(['<tr id="upload-'+ index +'">'
          ,'<td>'+ file.name +'</td>'
          ,'<td>'+ (file.size/1014).toFixed(1) +'kb</td>'
          ,'<td>等待上传</td>'
          ,'<td>'
            ,'<button class="layui-btn layui-btn-xs demo-reload layui-hide">重传</button>'
            ,'<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete">删除</button>'
          ,'</td>'
        ,'</tr>'].join(''));
        
        //单个重传
        tr.find('.demo-reload').on('click', function(){
          obj.upload(index, file);
        });
        
        //删除
        tr.find('.demo-delete').on('click', function(){
          delete files[index]; //删除对应的文件
          tr.remove();
          uploadListIns.config.elem.next()[0].value = ''; //清空 input file 值，以免删除后出现同名文件不可选
        });
        
        demoListView.append(tr);
      });
    }
    ,done: function(res, index, upload){
      if(res.code == 0){ //上传成功
        var tr = demoListView.find('tr#upload-'+ index)
        ,tds = tr.children();
        tds.eq(2).html('<span style="color: #5FB878;">上传成功</span>');
        tds.eq(3).html(''); //清空操作
        $('#layui-file').append('<input type="hidden" name="pc_src['+j+']" value="'+res.data['src']+'" />');
        $('#layui-file').append('<input type="hidden" name="pc_name['+j+']" value="'+res.data['name']+'" />');
        j++;
        return delete this.files[index]; //删除文件队列已经上传成功的文件

      }
      this.error(index, upload);
    }
    ,error: function(index, upload){
      var tr = demoListView.find('tr#upload-'+ index)
      ,tds = tr.children();
      tds.eq(2).html('<span style="color: #FF5722;">上传失败</span>');
      tds.eq(3).find('.demo-reload').removeClass('layui-hide'); //显示重传
    }
  });


 $(document).on("click", "a[name='appendix']", function (event) {
     var id = $(this).data('id'); //编辑
     var name = $(this).data('name'); //名称
     var type=$(this).data('type');//类别
     layer.confirm("确定删除"+name+"吗？", function (t) {
        $.ajax({
            'url':"{:url('customer/appendix_del')}",
            'type':"post",
            'data':{'id':id,'type':type},
            success:function(res){
                 if (res.code === 200) {
                      layer.msg(res.msg, {icon: 1});
                      window.location.reload()
                      layer.close(t); //关闭弹层
                  } else {
                        console.log(res);
                        layer.msg(res.msg, {icon: 5});
                        return false;
                  }
            }
        });
     });
 });
});
</script>